<template>
  <a-card :bordered="false">

    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">

          <a-col :md="6" :sm="8">
            <a-form-item label="业务KEY">
              <a-input placeholder="请输入业务KEY" v-model="queryParam.searchBusinesskey"></a-input>
            </a-form-item>
          </a-col>
          <!--<a-col :md="6" :sm="8">
            <a-form-item label="标识key">
              <a-input placeholder="请输入标识key" v-model="queryParam.key"></a-input>
            </a-form-item>
          </a-col>-->
          <!--<a-col :md="6" :sm="8">
            <a-form-item label="name">
              <a-input placeholder="请输入name" v-model="queryParam.name"></a-input>
            </a-form-item>
          </a-col>
        <template v-if="toggleSearchStatus">
        <a-col :md="6" :sm="8">
            <a-form-item label="key">
              <a-input placeholder="请输入key" v-model="queryParam.key"></a-input>
            </a-form-item>
          </a-col>
          <a-col :md="6" :sm="8">
            <a-form-item label="category">
              <a-input placeholder="请输入category" v-model="queryParam.category"></a-input>
            </a-form-item>
          </a-col>
          <a-col :md="6" :sm="8">
            <a-form-item label="createTime">
              <a-input placeholder="请输入createTime" v-model="queryParam.createTime"></a-input>
            </a-form-item>
          </a-col>
          </template>-->
          <a-col :md="6" :sm="8" >
            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
              <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>
              <!--<a @click="handleToggleSearch" style="margin-left: 8px">
                {{ toggleSearchStatus ? '收起' : '展开' }}
                <a-icon :type="toggleSearchStatus ? 'up' : 'down'"/>
              </a>-->
            </span>
          </a-col>

        </a-row>
      </a-form>
    </div>
    <!--<div  v-if="addModel">
    <iframe  :src="modelSrc" style="width: 100%;height: 500px" >
    </iframe>
    </div>-->
    <!-- 操作按钮区域 -->
    <!--<div class="table-operator">-->
      <!--<a-button @click="handleAdd" type="primary" icon="plus">新增</a-button>-->
      <!--&lt;!&ndash;<a-button type="primary" icon="download" @click="handleExportXls('模型管理')">导出</a-button>-->
      <!--<a-upload name="file" :showUploadList="false" :multiple="false" :headers="tokenHeader" :action="importExcelUrl" @change="handleImportExcel">-->
        <!--<a-button type="primary" icon="import">导入</a-button>-->
      <!--</a-upload>&ndash;&gt;-->
      <!--<a-dropdown v-if="selectedRowKeys.length > 0">-->
        <!--<a-menu slot="overlay">-->
          <!--<a-menu-item key="1" @click="batchDel"><a-icon type="delete"/>删除</a-menu-item>-->
        <!--</a-menu>-->
        <!--<a-button style="margin-left: 8px"> 批量操作 <a-icon type="down" /></a-button>-->
      <!--</a-dropdown>-->
    <!--</div>-->

    <!-- table区域-begin -->
    <div>
      <!-- <div class="ant-alert ant-alert-info" style="margin-bottom: 16px;">
        <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择 <a style="font-weight: 600">{{ selectedRowKeys.length }}</a>项
        <a style="margin-left: 24px" @click="onClearSelected">清空</a>
      </div> -->

      <a-table
        ref="table"
        size="middle"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        @change="handleTableChange">

        <span slot="action" slot-scope="text, record">
          <a @click="showHistory(record)">审批历史</a>
          <a-divider type="vertical" />
          <a @click="showMainProcess(record)">主要流程</a>
        </span>

        <!-- 字符串超长截取省略号显示-->
        <span slot="businessKey" slot-scope="text,record"><a-tooltip><template slot="title">{{text}}</template>{{Ellipsis(record)}}</a-tooltip></span>

      </a-table>
    </div>
    <!-- table区域-end -->

    <!-- 表单区域 -->
    <history-list ref="modalList" @ok="modalFormOk"></history-list>
    <main-process-history-list ref="processList" @ok="modalFormOk"></main-process-history-list>
    <!--<model-modal ref="modalForm" @ok="modalFormOk"></model-modal>-->
    <!--<model-edit-modal ref="modalEditForm"></model-edit-modal>-->
  </a-card>
</template>

<script>
  /*import ModelModal from './modules/ModelModal'*/
  import HistoryList from './modules/HistoryList'
  import MainProcessHistoryList from './modules/MainProcessHistoryList'
  import { JeecgListMixin } from '@/mixins/JeecgListMixin'
  import { getAction,deleteAction,putAction,postAction} from '@/api/manage'
  import moment from "moment"
  export default {
    name: "TodoList",
    mixins:[JeecgListMixin],
    components: {
      /*ModelModal,*/
      HistoryList,
      MainProcessHistoryList
      /*ModelEditModal*/
    },
    data () {
      return {
        description: '我的待办页面',
        // 表头
        columns: [
          // {
          //   title: '#',
          //   dataIndex: '',
          //   key:'rowIndex',
          //   width:60,
          //   align:"center",
          //   customRender:function (t,r,index) {
          //     return parseInt(index)+1;
          //   }
          //  },

		   /*{
            title: '模型ID',
            align:"center",
            dataIndex: 'id'
           },*/
          {
            title: '流程实例ID',
            align:"center",
            dataIndex: 'id'
          },
		      {
            title: '流程名称',
            align:"center",
            dataIndex: 'name'
           },
          {
            title: '业务KEY',
            align:"center",
            dataIndex: 'businessKey',
            width: 300,
            scopedSlots: {customRender: 'businessKey'}

          },
          {
            title: '当前任务环节',
            align:"center",
            dataIndex: 'taskName',
          },
          {
            title: '申请人',
            align:"center",
            dataIndex: 'startUserName'
          },
          {
            title: '开始时间',
            align:"center",
            dataIndex: 'startTime',
            customRender: (text, row, index) => {
              if (text != ''){
                return moment(text).format("YYYY-MM-DD HH:mm");
              }
            },
            sorter: true
          },
          {
            title: '状态',
            align:"center",
            dataIndex: 'suspensionState',
            customRender:function (t,r,index) {
              let status = ''
              if (r.suspensionState == 1) {
                status = '运行'
              } else if (r.suspensionState == 2) {
                status = '暂停'
              } else {
                status = '未知'
              }
              return status;
            }
          },

          /*{
            title: '创建时间',
            align:"center",
            dataIndex: 'task.createTime'
          },*/
          /*{
            title: '当前任务节点',
            align:"center",
            dataIndex: 'key'
          },*/
          /*{
            title: '版本',
            align:"center",
            dataIndex: 'version'
          },
          {
            title: '部署时间',
            align:"center",
            dataIndex: 'deployTime'
          },*/
		   /*{
            title: '模型分类',
            align:"center",
            dataIndex: 'category'
           },*/

          /*{
            title: '模型描述',
            align:"center",
            dataIndex: 'description'
          },*/
		   /*{
            title: 'createTime',
            align:"center",
            dataIndex: 'createTime'
           },*/
		   /*{
            title: 'lastUpdateTime',
            align:"center",
            dataIndex: 'lastUpdateTime'
           },
		   {
            title: 'version',
            align:"center",
            dataIndex: 'version'
           },
		   {
            title: 'metaInfo',
            align:"center",
            dataIndex: 'metaInfo'
           },
		   {
            title: 'deploymentId',
            align:"center",
            dataIndex: 'deploymentId'
           },
		   {
            title: 'editorSourceValueId',
            align:"center",
            dataIndex: 'editorSourceValueId'
           },
		   {
            title: 'editorSourceExtraValueId',
            align:"center",
            dataIndex: 'editorSourceExtraValueId'
           },
		   {
            title: 'tenantId',
            align:"center",
            dataIndex: 'tenantId'
           },*/
          {
            title: '操作',
            dataIndex: 'action',
            align:"center",
            scopedSlots: { customRender: 'action' },
          }
        ],
		url: {
          list: "/act/execution/running",
          delete: "/act/model/delete",
          deleteBatch: "/act/model/deleteBatch",
          exportXlsUrl: "model/model/exportXls",
          importExcelUrl: "model/model/importExcel",
       },
        addModel:true,
        modelSrc:'',
    }
  },
  computed: {
    importExcelUrl: function(){
      return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`;
    }
  },
    methods: {
      Ellipsis(record){
        if(record.businessKey==undefined || record.businessKey==null || record.businessKey==''){
          record.businessKey=" "
        }
        if(record.businessKey.length > 30){
          return record.businessKey.substring(0,30)+"..."

        }else {
          return record.businessKey
        }

      },
      showHistory(row){
        this.$refs.modalList.init(row.businessKey);
        this.$refs.modalList.title = "审批历史";
        this.$refs.modalList.disableSubmit = false;
      },
      showMainProcess(row){
        this.$refs.processList.init(row.businessKey);
        this.$refs.processList.title = "主要流程";
        this.$refs.processList.disableSubmit = false;
      }


    }
  }
</script>
<style scoped>
  @import '~@assets/less/common.less'
</style>